package com.umer.pinban.adapter.customer;

import android.content.Context;
import android.view.View;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.common.image.bean.ImageInfo;
import com.common.ui.recycleview.PullLoadMoreRecyclerView;
import com.common.ui.recycleview.adapter.RecyclerviewBasicPageAdapterTwo;
import com.common.ui.recycleview.base.ViewHolder;
import com.common.ui.recycleview.decoration.DividerGridItemDecoration;
import com.common.ui.recycleview.listener.DataStateListener;
import com.common.ui.recycleview.listener.OptListener;
import com.common.utils.Constants;
import com.common.utils.screen.DensityUtil;
import com.common.utils.screen.ScreenUtil;
import com.umer.pinban.R;
import com.umer.pinban.bean.customer.CustomerTailRecordBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 跟进记录
 */
public class CustomerTailRecordListAdapter extends RecyclerviewBasicPageAdapterTwo<CustomerTailRecordBean> {

    private int height;
    private OptListener optListener;

    public CustomerTailRecordListAdapter(Context context, int layoutId, PullLoadMoreRecyclerView pullLoadMoreRecyclerView
            , OptListener optListener, DataStateListener dataStateListener) {
        super(context, layoutId, pullLoadMoreRecyclerView,dataStateListener);
        pMRecyclerView = pullLoadMoreRecyclerView;
        this.dataStateListener = dataStateListener;
        this.optListener = optListener;
        int width = ScreenUtil.getInstance().getScreenWidth() - DensityUtil.getInstance().dpToPx(65);
        height = width/10;
    }

    @Override
    public void convert(ViewHolder holder, CustomerTailRecordBean customerTailRecordBean, int position) {
        TextView tv_name = holder.getView(R.id.tv_name);
        TextView tv_time = holder.getView(R.id.tv_time);
        TextView tv_record = holder.getView(R.id.tv_record);
        tv_name.setText(customerTailRecordBean.getPersonnelName());
        tv_time.setText(customerTailRecordBean.getCreateTime()+"");
        tv_record.setText(customerTailRecordBean.getRemark());
        RecyclerView recyclerView =  holder.getView(R.id.recycler);
        List<CustomerTailRecordBean.PicListBean> infos = customerTailRecordBean.getPicList();
        if(infos!=null && infos.size()>0){

            List<ImageInfo> imageInfoList = new ArrayList<>();
            for(int i=0;i<infos.size();i++){
                ImageInfo imageInfo = new ImageInfo();
                imageInfo.setOriginUrl(Constants.IP_PORT_DEFAULT_PICTURE +infos.get(i).getFilePath());
                imageInfo.setThumbnailUrl(Constants.IP_PORT_DEFAULT_PICTURE +infos.get(i).getFilePath());
                imageInfoList.add(imageInfo);
            }
            recyclerView.setVisibility(View.VISIBLE);
            CustomerRecordListPicAdapter customerRecordListPicAdapter =
                    new CustomerRecordListPicAdapter(context, infos,
                            R.layout.activity_customer_record_list_pic_item,height,optListener,imageInfoList);
            recyclerView.setLayoutManager(new GridLayoutManager(context, 10) {
                @Override
                public boolean canScrollVertically() {
                    //解决ScrollView里存在多个RecyclerView时滑动卡顿的问题
                    //如果你的RecyclerView是水平滑动的话可以重写canScrollHorizontally方法
                    return false;
                }
            });
            recyclerView.setAdapter(customerRecordListPicAdapter);
            recyclerView.addItemDecoration(new DividerGridItemDecoration(context));

        }else {
            recyclerView.setVisibility(View.GONE);
        }
    }
}
